package com.hzcx.app.simplechat.util.toast;

import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.hzcx.app.simplechat.MyApplication;

public class ToastUtils {

    public static void show(String msg) {
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            Toast.makeText(MyApplication.getContext(),msg,Toast.LENGTH_SHORT).show();
            return;
        }

        Handler mainHandler = new Handler(Looper.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                //已在主线程中，可以更新UI
                Toast.makeText(MyApplication.getContext(),msg,Toast.LENGTH_SHORT).show();
            }
        });
    }
}
